package 
{
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
	
	public class FriendsChooser extends TModalWindow
	{
		private var Modal: TModalWindow = null;
		private var Cont: TFriendsContainer = null;
		private var fOnChooseFriend: Function = null;
		
		private function OnCloseClick(e: MouseEvent): void
		{
			Close();
			Modal.Close();
		}
		
        private function OnFriendClick(e: MouseEvent): void
		{
			var O: Object = new Object();
			var C: TControl = Cont.FindControlByObjectTarget(e.target);
			O.Freind = C.Tag;
			
			if (fOnChooseFriend != null)
				fOnChooseFriend(O);
			OnCloseClick(e);
		}
		
		public function FriendsChooser(Info: TNaperstokInfo, anOnChooseFriend: Function)
		{ 
			Modal = new TModalWindow(0);
			
			super(0.9);
			
			var NewWidth: Number = (MR.Width / 3) * 2;
			var OldWidth: Number = MR.Width;
			MR.Width = NewWidth;
			MR.X = MR.X + (OldWidth - NewWidth) / 2;
			
			var NewHeight: Number = (MR.Height / 3) * 2;
			var OldHeight: Number = MR.Height;
			MR.Height = NewHeight;
			MR.Y = MR.Y + (OldHeight - NewHeight) / 2;
			
			var CloseBtn: InvControl = new InvControl(res.close, this, MR.X + MR.Width - 13, MR.Y + 5);
			CloseBtn.addEventListener(MouseEvent.CLICK, OnCloseClick);
			
			Cont = new TFriendsContainer(this, MR.X, MR.Y, MR.Width - 20, MR.Height, Info, OnFriendClick);
			Cont.SetLinesCount(4);
			Cont.ScrollByOneItem = false;
			
			fOnChooseFriend = anOnChooseFriend;
		}
		
	}
	
}